package com.furniture.ui.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.furniture.R;
import com.furniture.Utils;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 更多选项
 * Created by Bob on 2016/3/16.
 */
public class GoodContextMenu extends LinearLayout {
    private static final int CONTEXT_MENU_WIDTH = Utils.dpToPx(240);

    private int goodItem = -1;

    private OnGoodContextMenuItemClickListener onItemClickListener;

    public GoodContextMenu(Context context) {
        super(context);
        init();
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.view_context_menu, this, true);
        setBackgroundResource(R.drawable.bg_container_shadow);
        setOrientation(VERTICAL);
        setLayoutParams(new LayoutParams(CONTEXT_MENU_WIDTH, ViewGroup.LayoutParams.WRAP_CONTENT));
    }

    public void bindToItem(int goodItem) {
        this.goodItem = goodItem;
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        ButterKnife.bind(this);
    }

    public void dismiss() {
        ((ViewGroup) getParent()).removeView(GoodContextMenu.this);
    }

    @OnClick(R.id.btnReport)
    public void onReportClick() {
        if (onItemClickListener != null) {
            onItemClickListener.onDeleteClick(goodItem);
        }
    }

//    @OnClick(R.id.btnSharePhoto)
//    public void onSharePhotoClick() {
//        if (onItemClickListener != null) {
//            onItemClickListener.onShareGoodClick(goodItem);
//        }
//    }

    @OnClick(R.id.btnCopyShareUrl)
    public void onCopyShareUrlClick() {
        if (onItemClickListener != null) {
            onItemClickListener.onCopyGoodUrlClick(goodItem);
        }
    }

    @OnClick(R.id.btnCancel)
    public void onCancelClick() {
        if (onItemClickListener != null) {
            onItemClickListener.onCancelClick(goodItem);
        }
    }

    public void setOnGoodMenuItemClickListener(OnGoodContextMenuItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnGoodContextMenuItemClickListener {
        public void onDeleteClick(int goodItem);

//        public void onShareGoodClick(int goodItem);

        public void onCopyGoodUrlClick(int goodItem);

        public void onCancelClick(int goodItem);
    }
}